<?php

namespace App\Http\Requests\Admin\Admin;

use Illuminate\Foundation\Http\FormRequest;

class AdminCreate extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * 定义表单规则
     *
     * Date: 2018/06/08
     * @author Tenny
     * @return array
     */
    public function rules()
    {
        return [
            'name' => 'required',
            'phone' => ['required', 'regex:/^(1[3456789])\d{9}$/','unique:admin,phone'],
            'password' => 'required|min:6|max:18',
            'role_name' => 'required',
        ];
    }

    /**
     * 定义错误响应消息
     *
     * Date: 2018/06/08
     * @author Tenny
     * @return array
     */
    public function messages()
    {
        return [
            'name.required' => '请输入姓名',
            'phone.required' => '请输入手机号',
            'phone.regex' => '您输入的手机号码不合法',
            'phone.unique' => '您输入的手机号码已存在',
            'password.required' => '请输入密码',
            'password.min' => '密码不得少于:min个字符',
            'password.max' => '密码不得超过:max个字符',
            'role_name.required' => '请输入角色名',
        ];
    }
}
